package com.sunlands.qdcy.tongzhuo.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Date;

/**
 * @author gaoyanfeng
 * @description: 日志的回复
 * @date 2019/5/2914:21
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "tz_user_diary_reply")
@JsonSerialize
@DynamicUpdate
@DynamicInsert
@ApiModel(value = "回复信息表")
public class UserDiaryReplyDO {

    @Id
    @GeneratedValue
    @ApiModelProperty(value = "回复id")
    private Long id;

    @ApiModelProperty(value = "日记id")
    private Long diaryId;

    @ApiModelProperty(value = "评论id")
    private Long commentId;

    @ApiModelProperty(value = "回复用户id")
    private Long replyUserId;

    @ApiModelProperty(value = "回复内容")
    private String replyContent;

    @ApiModelProperty(value = "被回复的id")
    private Long replyedId;

    @ApiModelProperty(value = "被回复用户id")
    private Long replyedUserId;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    @ApiModelProperty(value = "1:日记的回复，2:评论的回复，3:回复的回复")
    private Integer type;

    @ApiModelProperty(value = "1:正常，0:逻辑删除")
    private Integer status;

    public enum TypeEnums {
        /**
         * 日记评论类型
         */
        DIARY_COMMENT(1, "日记的回复"),
        REPLY_COMMENT(2, "评论的回复"),
        REPLY_REPLY(3, "回复的回复"),
        ;

        public final Integer code;
        public final String desc;

        TypeEnums(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public static UserDiaryReplyDO.TypeEnums create(Integer code) {
            if (null == code) {
                return null;
            }
            for (UserDiaryReplyDO.TypeEnums field : UserDiaryReplyDO.TypeEnums.values()) {
                if (code.intValue() == field.getCode()) {
                    return field;
                }
            }
            return null;
        }

        public Integer getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }
    }

}
